<?php
/*
 * Copyright 2010 Johannes M. Schmitt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/**
 * Includes the Javascripts necessary to load the given application
 * 
 * @param string $applicationName
 * TODO: Find a more generic way to determine the public path, currently this
 *       only works, if the web root is the top directory accessible by /.
 * TODO: This needs to be refactored to load a specific application
 */
function include_closure_base()
{
	$debug = sfConfig::get('sf_debug', false);
	
	if ($debug === true)
	{
		$loadJs = '<script language="javascript" type="text/javascript" src="/sfClosureToolsPlugin/js/closure/closure/goog/base.js"></script>';
		
		$webDir = sfConfig::get('sf_web_dir');
		if (file_exists($webDir.'/js/compiled/deps.js'))
		{
			$loadJs = '<script language="javascript" type="text/javascript">'
									.'CLOSURE_NO_DEPS = true;'
							 .'</script>'.$loadJs
							 .'<script language="javascript" type="text/javascript" src="/js/compiled/deps.js"></script>';
			
		}
		
		echo $loadJs;
	}
	else
	{
		echo '';
	}
}

/**
 * Adds a closure related stylesheet to the response
 * @param string $name
 * 
 * TODO: Add an option to overwrite the default Google Closure stylesheet
 */
function use_closure_stylesheet($name) 
{
	use_stylesheet('/sfClosureToolsPlugin/js/closure/closure/goog/css/'.$name);
}
